import hashlib

def update_model(model, new_params, expected_hash):
    """
    安全更新模型
    :param model: 当前模型
    :param new_params: 新的模型参数
    :param expected_hash: 预期的哈希值
    :return: 更新后的模型
    """
    new_params_hash = hashlib.sha256(new_params).hexdigest()
    if new_params_hash != expected_hash:
        raise ValueError("Invalid update")
    model.update(new_params)
    return model

# 示例
model = "YourModel"
new_params = b"new_model_weights"
expected_hash = hashlib.sha256(new_params).hexdigest()
updated_model = update_model(model, new_params, expected_hash)
print(f"Updated model: {updated_model}")